package com.cdtye.itps.cms.util;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

/**
 * @Author: wangzhong
 * @Date: 2023/6/30 12:32
 * @Description:
 **/

public class JasyptUtil {
    public static StringEncryptor jasyptEncryptor() {

        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();

        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword("cms");
        config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
//        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("5");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);

        return encryptor;
    }
    public static void main(String[] args){
        StringEncryptor encryptor = jasyptEncryptor();
        //需要加密数据
        String plaintext="SH_shjj_2022";
        String eText = "DUuXcSP1wsmyPWVdRKEPGSNtA2sXKRmEqCSfbbVQ/PZMeLzlCqWSyu7shKGzWMEw";
        //加密
        String encrypttext=encryptor.encrypt(plaintext);
        System.out.println( encrypttext);
        plaintext = encryptor.decrypt(eText);
        System.out.println( plaintext);
    }
}
